<?php

class course extends Controller {

	function course()
	{
		parent::Controller();	
	}
	
	function index()
	{
		$this->load->model('filemanagementmodel');
	    $data['header_tel'] = $this->filemanagementmodel->getByPostion('header_tel');
	    $data['footer_address'] = $this->filemanagementmodel->getByPostion('footer_add1');
		
		for($i = 1; $i <= 7; $i++) {
			$n = 'l01_0'.$i;
			$data[$n] =  $this->filemanagementmodel->getByPostion($n);
	    }
	    
		for($i = 1; $i <= 10; $i++) {
			if($i == 10)
				$n = 'l02_'.$i;
			else 
				$n = 'l02_0'.$i;
			$data[$n] =  $this->filemanagementmodel->getByPostion($n);
	    }
	    
		for($i = 1; $i <= 7; $i++) {
			$n = 'l03_0'.$i;
			$data[$n] =  $this->filemanagementmodel->getByPostion($n);
	    }
	    
		for($i = 1; $i <= 10; $i++) {
			if($i == 10)
				$n = 'l04_'.$i;
			else
				$n = 'l04_0'.$i;
			$data[$n] =  $this->filemanagementmodel->getByPostion($n);
	    }
	    
		$this->load->view('f_header', $data);
		$this->load->view('f_course', $data);
		$this->load->view('f_footer', $data);
	}
	
	function edit()
	{
		if ($this->session->userdata('logged_in') != TRUE)
	    {
	        redirect('login/index');
	    }
		
	    $this->load->model('filemanagementmodel');
	    
		for($i = 1; $i <= 7; $i++) {
			$n = 'l01_0'.$i;
			$data[$n] =  $this->filemanagementmodel->getByPostion($n);
	    }
	    
		for($i = 1; $i <= 10; $i++) {
			if($i == 10)
				$n = 'l02_'.$i;
			else 
				$n = 'l02_0'.$i;
			$data[$n] =  $this->filemanagementmodel->getByPostion($n);
	    }
	    
		for($i = 1; $i <= 7; $i++) {
			$n = 'l03_0'.$i;
			$data[$n] =  $this->filemanagementmodel->getByPostion($n);
	    }
	    
		for($i = 1; $i <= 10; $i++) {
			if($i == 10)
				$n = 'l04_'.$i;
			else
				$n = 'l04_0'.$i;
			$data[$n] =  $this->filemanagementmodel->getByPostion($n);
	    }
	    
		$this->load->view('header');
		$this->load->view('f_course_edit',$data);
	}
	
	function save()
	{
		if ($this->session->userdata('logged_in') != TRUE)
	    {
	        redirect('login/index');
	    }
	    
	    $this->load->model('filemanagementmodel');
	    
	    for($i = 1; $i <= 7; $i++) {
	    	$data['position'] = 'l01_0'.$i;
	    	$data['file_name'] = $this->input->post($data['position']);
	    	$this->filemanagementmodel->update($data);
	    }
	    
		for($i = 1; $i <= 10; $i++) {
			if($i == 10)
				$data['position'] = 'l02_'.$i;
	    	else 
	    		$data['position'] = 'l02_0'.$i;
	    	$data['file_name'] = $this->input->post($data['position']);
	    	$this->filemanagementmodel->update($data);
	    }
	    
		for($i = 1; $i <= 7; $i++) {
	    	$data['position'] = 'l03_0'.$i;
	    	$data['file_name'] = $this->input->post($data['position']);
	    	$this->filemanagementmodel->update($data);
	    }
	    
		for($i = 1; $i <= 10; $i++) {
			if($i == 10)
				$data['position'] = 'l04_'.$i;
	    	else 
	    		$data['position'] = 'l04_0'.$i;
	    	$data['file_name'] = $this->input->post($data['position']);
	    	$this->filemanagementmodel->update($data);
	    }
		
		$this->edit();
	}
}

?>